Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ticket/nnnn/sync/stim/aligner #2354

Merged
merged 5 commits into from
Apr 8, 2022
Merged

Conversation

danielsf
Copy link
Contributor

@danielsf danielsf commented Apr 7, 2022

This PR ultimately adds the utility function

allensdk.brain_observatory.sync_stim_aligner.get_start_frames_from_stimulus_blocks

which is needed to scan a single sync file and find the indices of the starting frames for the behavior_, mapping_, and replay_ stimulus blocks from a single sync file. It is, ultimately, a re-implementation of the method here

https://github.com/AllenInstitute/ecephys_etl_pipelines/blob/main/src/ecephys_etl/modules/vbn_create_stimulus_table/create_stim_table.py#L132-L225

I chose not to make ecephys_etl_pipelines a dependency of the SDK because

  1. I believe we are going to need the flexibility to get_vsyncs from either the rising (in the case of things like running speed or rewards) or falling (in the case of stimulus presentations) edges of the sync file. The ecephys_etl code as implemented does not afford that flexibility

  2. I wasn't sure how to guard against the ecephys_etl implementation changing out from under the SDK unexpectedly.

If it makes anyone feel better, ecephys_etl just copied sync_dataset.py from the SDK (which copied sync_dataset.py from some BitBucket repository somewhere).

In order to support this work, I had to break up our StimulusFile data objects into three classes.

BehaviorStimulusFile
ReplayStimulusFile
MappingStimulusFile

to represent the three varieties of stimulus file in the VBN experiments. The differences between the three come in how they are represented in our JSON serializations and how num_frames is accessed.

BehaviorStimulusFile corresponds to the StimulusFile class that was implemented for the VBO release.

The proper use of get_start_frames_from_stimulus_blocks is something like

from allensdk.brain_observatory.sync_stim_aligner import (
    _get_rising_times,
    get_start_frames_from_stimulus_blocks)

with SyncDataset(sync_path) as sync_data:
    frame_times = _get_rising_times(sync_data, sync_lines='vsync_stim')

start_frames = get_start_frames_from_stimulus_blocks(
                                    stimulus_files=[behavior_stim, mapping_stim, replay_stim],
                                    sync_file=sync_path,
                                    ...)

timesteps_for_behavior = frame_times[start_frames[0]: start_frames[0]+behavior_stim.num_frames()]
timesteps_for_replay = frame_times[start_frames[2]:start_frames[2]+replay_stim.num_frames()]

danielsf added 2 commits April 7, 2022 14:07
We are going to need to implement different varieties of StimulusFile
sub-classes to represent the other pickle files involved in the VBN
data. I did not want any VBO code to accidentally use these new
classes.
each has its own way of access num_frames and its own
dict_repr key for use in from_json and to_json

all inherity from _StimulusFile base class
@danielsf danielsf force-pushed the ticket/NNNN/sync/stim/aligner branch from 082eaf9 to 22c19b4 Compare April 7, 2022 21:28
@danielsf danielsf requested review from aamster, sgratiy and morriscb and removed request for aamster April 7, 2022 21:34
@danielsf danielsf force-pushed the ticket/NNNN/sync/stim/aligner branch from 9cc68de to ee5a593 Compare April 8, 2022 16:22
Copy link
Contributor

@morriscb morriscb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I think I've to one question and a comment that you should remove the explicit return None from a few functions.

full_msg += f"\nfilepath: {self.filepath}"
raise RuntimeError(full_msg)

return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to explicitly return None as far as I know.

line=chosen_line,
units='seconds')

valid = (falling_edges > rising_edges[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed that these two arrays are the same length?


# fill lineA and lineB with random bits
rng = np.random.default_rng(66123)
indexes = np.arange(0, n_samples, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three here looks to be also used on line 60. I realize this is in a fixture, but if you are use the same value in multiple places (and they need to be changed together if one changes) you should specify it as a variable.

Note: ended up wrapping test clean up code in try/except block

the windows CI processes are still getting PermissionErrors
cleaning up temporary files. That should not block building/deploying

make sure string gets passed to safe_system_path
@danielsf danielsf force-pushed the ticket/NNNN/sync/stim/aligner branch from ec766ba to d7ee556 Compare April 8, 2022 20:19
@danielsf danielsf merged commit a087638 into vbn_2022_dev Apr 8, 2022
@danielsf danielsf deleted the ticket/NNNN/sync/stim/aligner branch April 25, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants